package com.xintoucloud.pbs.dao.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;

import com.xintoucloud.pbs.dao.NewsTopicManagementDao;
import com.xintoucloud.pbs.entity.DynamicNewsTopic;

@Repository
public class NewsTopicManagementDaoImpl implements NewsTopicManagementDao {
	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public List<DynamicNewsTopic> list() {
		List<DynamicNewsTopic> list = sessionFactory.getCurrentSession().createQuery("from DynamicNewsTopic").list();
		return list;
	}

	@Override
	public Serializable add(DynamicNewsTopic d) {
		return sessionFactory.getCurrentSession().save(d);
	}


	@Override
	public void update(DynamicNewsTopic d) {
		DynamicNewsTopic old = getOne(d.getNtid());
		old.setTname(d.getTname());
		//sessionFactory.getCurrentSession().update(d.getTname(), DynamicNewsTopic.class);
		//return 1;
	}

	@Override
	public DynamicNewsTopic getOne(int ntid) {
		DynamicNewsTopic d = sessionFactory.getCurrentSession().get(DynamicNewsTopic.class, ntid);
		return d;
	}

	@Override
	public boolean delete(int ntid) {
		DynamicNewsTopic d = getOne(ntid);
		try {
			sessionFactory.getCurrentSession().delete("要删除的实体名", d);
		}catch (Exception e) {
			System.out.println("删除不成功");
			return false;
		}
		return true;
	}

}
